// Copyright  2004-2008 Backplane Ltd.
//
// This file is part of Ubiquity formsPlayer
//
// Ubiquity formsPlayer is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
//
// Ubiquity formsPlayer is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License
// along with Ubiquity formsPlayer If not, see <http://www.gnu.org/licenses/>.
//	
//
//   Purpose: implementation of CXFormsParseDispatch.
//   $Id$


#include "stdafx.h"
#include "parseDispatch.h"

#include "actionDispatch.h"
#include "ImplContextualValue.h"
#include "tags.h"

	CXFormsParseDispatch::CXFormsParseDispatch(CImplActionDispatch* pImpl)
		: CXFormsParseAction( pImpl)
	{
		addAttributeCheck(ATTR_NAME, &pImpl->m_sName,false);
		addAttributeCheck(ATTR_TARGET, &pImpl->m_sTarget,false);
		addAttributeCheck(ATTR_BUBBLES, (LPVOID*)&pImpl->m_bBubbles,XFormsParse::parseXSDBoolean);
		addAttributeCheck(ATTR_CANCEL, (LPVOID*)&pImpl->m_bCancelable,XFormsParse::parseXSDBoolean);

	}

	
void CXFormsParseDispatch::CheckElement(IHTMLElement *pElem, BSTR bstrTag, CImpl* pImpl)
{
	if (wcscmp(bstrTag, L"name") == 0)
	{
		CImplContextualValue * pCV = new CImplContextualValue();
		CComVariant vtTemp;
		pElem->getAttribute(L"value",1,&vtTemp);
		vtTemp.CopyTo(&pCV->m_sValueExpression);
		CImplActionDispatch * pDisp = dynamic_cast<CImplActionDispatch*>(pImpl);
		if(pDisp)
			pDisp->m_pNameResolver = pCV;
	}
	else if (wcscmp(bstrTag, L"target") == 0)
	{
		CImplContextualValue * pCV = new CImplContextualValue();
		CComVariant vtTemp;
		pElem->getAttribute(L"value",1,&vtTemp);
		vtTemp.CopyTo(&pCV->m_sValueExpression);
		CImplActionDispatch * pDisp = dynamic_cast<CImplActionDispatch*>(pImpl);
		if(pDisp)
			pDisp->m_pTargetResolver = pCV;
	}
}
